<!-- 分类授权编辑页面 -->
{extend name="public/base" /}
{block name="body"}
<div class="row">
    <div class="col-xs-12">
        <div class="tab-wrap">
            <ul class="tab-nav nav nav-tabs">
                <li><a href="{:url('AuthManager/access',array('group_name'=>input('group_name') ,'group_id'=> input('group_id')))}">访问授权</a></li>
                <li class="active"><a href="javascript:;">分类授权</a></li>
                <li><a href="{:url('AuthManager/user',array('group_name'=>input('group_name') ,'group_id'=> input('group_id')))}">成员授权</a></li>
                <li class="pull-right">
                    <select class="form-control" name="group">
                        {volist name="auth_group" id="vo"}
                            <option value="{:url('AuthManager/category',array('group_id'=>$vo['id'],'group_name'=>$vo['title']))}" {eq name="vo['checked']" value="true"}selected{/eq} >{$vo.title}</option>
                        {/volist}
                    </select>
                </li>
            </ul>
            <!-- 表格列表 -->
            <div class="tb-unit posr margin-top-10">
                <!--<form class="save-category" action="{:url('AuthManager/addToCategory')}" method="post" enctype="application/x-www-form-urlencoded">-->
                    <input type="hidden" name="group_id" value="{:input('group_id')}">

                    <ul id="treeDemo" class="ztree"></ul>

                    <div class="tb-unit-bar">
                        <button class="btn btn-danger ajax-posts" type="submit" target-form="save-category">确 定</button>
                        <button class="btn btn-success" onclick="javascript:history.back(-1);return false;">返 回</button>
                    </div>
                <!--</form>-->
            </div>
        </div>
    </div>
</div>
<!-- /表格列表 -->
{/block}
{block name="script"}
<link rel="stylesheet" href="__STATIC__/zTree/css/zTreeStyle/zTreeStyle.css" type="text/css">
<script type="text/javascript" src="__STATIC__/zTree/js/jquery.ztree.core.js"></script>
<script type="text/javascript" src="__STATIC__/zTree/js/jquery.ztree.excheck.js"></script>
<script type="text/javascript" >

    var setting = {
        view: {
            showIcon: false
        },
        check: {
            enable: true
        },
        data: {
            key: {
                name:"title",
                url:"delurl"
            },
            simpleData: {
                enable: true,
                idKey: "id",
                pIdKey: "pid",
                rootPId: 0
            }
        }
    };

    var zNodes ={:json_encode($category_list)};

    $(document).ready(function(){
        var treeObj = $.fn.zTree.init($("#treeDemo"), setting, zNodes);
        treeObj.expandAll(true);//默认展开

        $(".ajax-posts").click(function(){
            var nodes = treeObj.getCheckedNodes(true),
                group_id = $("input[name='group_id']").val();
            data=[];
            for (var i = 0; i < nodes.length; i++) {
                data[i] = nodes[i].id;
            }
            $.post("{:url('AuthManager/addToCategory')}",{'cid':data,'group_id':group_id}).done(function(data){
                if(data.code == 1){
                    layer_success(data.msg);
                    setTimeout(function(){
                        location.reload();
                    },1500);
                }else{
                    layer_error(data.msg);
                }
            });
        });
        $('select[name=group]').change(function(){
            location.href = this.value;
        });
        //导航高亮
        highlight_subnav('{:url('AuthManager/index')}');
    });
</script>
{/block}
